from flask import Flask
from App.view import blue
from .exist import exist_init
import sys
from pymongo import MongoClient
from config.config_db import Config
sys.path.append("..")#将上级目录加入python的扫描路径中

# init=>初始化flask以及导包
def create_app():
    app = Flask(__name__)
    # 蓝图注册
    app.register_blueprint(blueprint=blue)

    # mysql数据库配置
    #db_uri='mysql+pymysql://root:20223176@26.96.81.162:3306/usermessage'
    db_uri=f"mysql+pymysql://{Config.MYSQL_USERNAME}:{Config.MYSQL_PASSWORD}@{Config.MYSQL_HOST}:{Config.MYSQL_PORT}/{Config.MYSQL_DB}"
    app.config['SQLALCHEMY_DATABASE_URI']=db_uri
    app.config['SQLALCHEMY_TRACE_MODIFICATIONS']=False
    
    # 扩展包的初始化
    exist_init(app=app)
    return app

